package com.bigShen.jdbc.basic.dao;

import java.sql.*;

/**
 * @author : lei.shen
 * @date : 2018/11/19
 */
public class BaseDao {

    private static final String DRIVER_CLASS = "oracle.jdbc.driver.OracleDriver";
    private static final String DB_URL = "jdbc:oracle:thin:@127.0.0.1:1521:HTBK";
    private static final String USER_NAME = "TRD_CAMS";
    private static final String PASSWORD = "xpar";

    static {
        try {
            Class.forName(DRIVER_CLASS);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {

        return DriverManager.getConnection(DB_URL, USER_NAME, PASSWORD);

    }

    public static void closeAll(Connection connection, PreparedStatement statement, ResultSet rs) {

       if (null != rs) {
           try {
               rs.close();
           } catch (SQLException e) {
               e.printStackTrace();
           }
       }

        if (null != statement) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (null != connection) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
